# curl -C - -L --header "Authorization: Bearer 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" -o model-00001-of-00003.safetensors https://huggingface.co/meta-llama/Llama-2-13b-chat-hf/resolve/main/model-00001-of-00003.safetensors?download=true



"""
curl -C - 
-L --header "Authorization: Bearer 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" 
-o model-00001-of-00003.safetensors 
https://huggingface.co/meta-llama/Llama-2-13b-chat-hf/resolve/main/model-00001-of-00003.safetensors?download=true
"""

TOKEN = "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"
TAIL = " && \\"

def RebuildCmd(author:str,project:str,filename:str):
    global TOKEN, TAIL
    cmd01 = f"curl -C - -L --header \"Authorization: Bearer {TOKEN}\" "
    cmd02 = f"-o {filename} "
    cmd03 = f"https://huggingface.co/{author}/{project}/resolve/main/{filename}?download=true"
    cmd = cmd01 + cmd02 + cmd03
    cmd = cmd + TAIL
    print(cmd)
    return cmd

def ParseUrl(url:str):
    url = url.removeprefix("https://huggingface.co/")
    url = url.removesuffix("?download=true")
    # print(url)
    splist = url.split("/")
    # print(splist)
    if len(splist) == 5:
        assert splist[2] == "resolve"
        assert splist[3] == "main"
    author = splist[0]
    project = splist[1]
    filename = splist[-1]
    RebuildCmd(author,project,filename)
    pass


all = []
with open("url.txt","r",encoding="utf-8") as fp:
    for one in fp.readlines():
        one = one.strip()
        if len(one) > 0 and one.startswith("http"):
            all.append(one)

for one in all:
    ParseUrl(one)
# ['meta-llama', 'Llama-2-13b-hf', 'resolve', 'main', '.gitattributes']




